<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'home-stat', //页面标示
    'pagename' => '访问统计', //当前页面名称
    'mycss' => array(), //加载的css样式表
    'myjs' => array(), //加载的js脚本
	'footerjs'=>array('content/highcharts', 'content/exporting','content/combodate/moment.min','content/combodate/combodate','content/calendar'),
    'head' => true, //加载头部文件
);


include getTpl('header', 'public');
?>
<!--顶部导航 开始-->
<?php include getTpl('top', 'public');?>
<!--顶部导航 结束-->
<!--左侧菜单 开始-->
<?php include getTpl('nav', 'public');?>
<!--左侧菜单 结束-->
<!--主体 开始-->
<!-- content -->
<section id="content">
<!-- main padder --> 
<section class="main padder">
<div class="clearfix"> 
    <h4><i class="fa fa-table"></i><?php echo trim($Document['pagename'],'_');?></h4> 
</div>
<!--0-->
<section class="panel"  style="padding-bottom:10px">
<div class="panel-body" style="padding-bottom:0">
<div class="col-sm-6">
    开始时间：
    <input type="text" class="form-control" id="starttime" style=" width:130px;display:inline-block; margin-right:1em; " value="<?php echo outTime($time['starttime'],2);?>" onclick="new Calendar().show(this);" />
    结束时间：
    <input type="text" class="form-control" id="endtime" style=" width:130px;display:inline-block;" value="<?php echo outTime($time['endtime'],2);?>" onclick="new Calendar().show(this);" />
    <a class="btn btn-default" id="search" style="text-align:center; margin-right:20px">查询</a>
    <a class="btn btn-default" target="_blank" href="<?php echo U('home/statdonwload',array('starttime'=>$time['starttime'],'endtime'=>$time['endtime']));?>">导出</a>
</div>
</div>
</section>
<!--0-->
<div class="row">
<!-- table 11 -->
<div class="col-lg-12"> 
<section class="panel"> 
<header class="panel-heading">
访问统计
</header>
<div class="panel-body"> 
    <div class="row text-small"> 
        <div class="col-sm-12 m-b-mini">
        <div id="container" style="margin:5px auto"></div>
        </div>
    </div> 
</div>
<div class="table-responsive"> 
<table class="table table-striped b-t text-small"> 
  <thead> 
      <tr>
      <th align="center">ID</th>
      <th align="center">消息总数</th>
      <th align="center">新增用户</th>
      <th align="center">入住用户</th>
      <th align="center">入住率</th>
      <th align="center">当日关注流失</th>
      <th align="center">当日总体流失</th>
      <th align="center">当日净增</th>
      <th align="center">当日总体净增</th>
      <th align="center">来源分析</th>
      <th align="center">统计日期</th>
      <th align="center">&nbsp;</th>
    </tr>
  </thead> 
  <tbody> 
      <?php
      if ($rs){
          foreach($rs as $val){
      ?><tr>
          <td valign="middle"><?php echo $val['id'];?></td>
          <td valign="middle"><?php echo $val['new_msg'];?></td>
          <td valign="middle"><?php echo $val['new_user'];?></td>
          <td valign="middle"><?php echo $val['isbind'];?></td>
          <td valign="middle">
          <?php
          if($val['new_user']>0){
              echo ceil($val['isbind']/$val['new_user']*100)."%";
          }else{
              echo "无";	
          }
          ?>
          </td>
          <td valign="middle"><?php echo $val['today_new_cancel'];?></td>
          <td valign="middle"><?php echo $val['new_cancel'];?></td>
          <td valign="middle"><?php echo ($val['new_user']-$val['today_new_cancel']);?></td>
          <td valign="middle"><?php echo ($val['new_user']-$val['new_cancel']);?></td>
          
          <td valign="middle"><?php echo "微信关注：".$val['source0']."<br/>二维码扫描：".$val['source1']."<br/>网站二维码：".$val['source2']."<br/>其他：".$val['source3'];?></td>
          <td valign="middle"><?php echo ($val['infotime']?outTime($val['infotime'],2):'');?></td>
          <td align="center" valign="middle"><a href="<?php echo U('home/stat',array("id"=>$val['id']));?>">详细</a></td>
        </tr>
        <?php
          }
      }else{
        ?>
       <tr>
          <td colspan="20" align="center">暂无数据</td>
        </tr>
      <?php
      }?>
      </tbody> 
</table> 
</div> 
 <footer class="panel-footer"> 
    <div class="row"> 
        <div class="col-sm-12 text-right text-center-sm"> 
                <?php if(!isHave($model)){?>
                <?php echo page($total,$p,'',20,'p');?>
                <?php } ?>
        </div> 
    </div> 
</footer>
</section> 
</div> 
<!--/ table 11 -->

</div> 
</section>
<!--/ main padder -->  
</section> 
<!--/ content --> 
<!--主体 结束-->
<?php
if ($rs){
?>
<script>
	function datetime_to_unix(datetime){ 
	    datetime=datetime+"-0";
		var tmp_datetime = datetime.replace(/:/g,'-'); 
		tmp_datetime = tmp_datetime.replace(/ /g,'-'); 
		var arr = tmp_datetime.split("-"); 
		var now = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8)); 
		return parseInt(now.getTime()/1000); 
	} 
$(function () {
        $('#container').highcharts({
            chart: {
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: '用户访问走势分析',
                x: -20 //center
            },
            subtitle: {
                text: '',
                x: -20,
				y:5
            },
            xAxis: {
                categories: [<?php echo "'".implode("','",$data['time'])."'";?>]
            },
            yAxis: {
                title: {
                    text: '数据走势（人）'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: ''
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
            series: [{
                name: '新增用户',
                data: [<?php echo implode(',',$data['new_user']);?>]
            },{
                name: '入住用户',
                data: [<?php echo implode(',',$data['isbind']);?>]
            },{
                name: '当日流失',
                data: [<?php echo implode(',',$data['today_new_cancel']);?>]
            },{
                name: '总体流失',
                data: [<?php echo implode(',',$data['new_cancel']);?>]
            },{
                name: '当日净增',
                data: [<?php echo implode(',',$data['today_new_user']);?>]
            }]
        });
		
		$('#search').click(function(){
			starttime =datetime_to_unix($('#starttime').val());
			endtime = datetime_to_unix($('#endtime').val());
			asd=endtime-starttime;
			if((asd/86400)>31){
			    alert("对不起，查询日期需小于31天");	
			}else{
				location.href='stat.html?starttime='+starttime+'&endtime='+endtime;
			}
		});
		
    });
</script>
<?php
}
?> 
<script>
$(function(){

})
</script>
<?php
include getTpl('footer', 'public');
?>